<?php

namespace addons\yunfood;

use app\common\library\Menu;
use think\Addons;
use think\Loader;

/**
 * 插件
 */
class Yunfood extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'yunfood',
                'title'   => '扫码点餐',
                'icon'    => 'fa fa-cubes',
                'sublist' => [
                    [
                        'name'    => 'yunfood/dashboard',
                        'title'   => '数据概览',
                        'icon'    => 'fa fa-dashboard',
                        'weigh'   => 140,
                        'sublist' => [
                            ['name' => 'yunfood/dashboard/index', 'title' => '数据概览'],
                            ['name' => 'yunfood/dashboard/shopData', 'title' => '门店数据'],
                            ['name' => 'yunfood/dashboard/orderStat', 'title' => '订单统计'],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/workbench',
                        'title'   => '工作台',
                        'icon'    => 'fa fa-desktop',
                        'weigh'   => 130,
                        'sublist' => [
                            ['name' => 'yunfood/workbench/index', 'title' => '工作台'],
                            ['name' => 'yunfood/workbench/recentData', 'title' => '最近下单'],
                            ['name' => 'yunfood/workbench/shopData', 'title' => '门店数据'],
                            ['name' => 'yunfood/workbench/noticeData', 'title' => '新订单通知'],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/config',
                        'title'   => '系统设置',
                        'icon'    => 'fa fa-cogs',
                        'weigh'   => 120,
                        'sublist' => [
                            ['name' => 'yunfood/config/index', 'title' => '基础设置'],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/user_card',
                        'title'   => '用户管理',
                        'icon'    => 'fa fa-user',
                        'weigh'   => 110,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/user',
                                'title'   => '用户列表',
                                'icon'    => 'fa fa-list',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/user/index', 'title' => '查看'],
                                    ['name' => 'yunfood/user/add', 'title' => '新增'],
                                    ['name' => 'yunfood/user/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/user/del', 'title' => '删除'],
                                    ['name' => 'yunfood/user/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/fund/user',
                                'title'   => '储值账户',
                                'icon'    => 'fa fa-vcard',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/fund/user/index', 'title' => '查看'],
                                    ['name' => 'yunfood/fund/user/add', 'title' => '新增'],
                                    ['name' => 'yunfood/fund/user/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/fund/user/del', 'title' => '删除'],
                                    ['name' => 'yunfood/fund/user/multi', 'title' => '批量更新'],
                                    ['name' => 'yunfood/fund/user/plus', 'title' => '增加金额'],
                                    ['name' => 'yunfood/fund/user/minus', 'title' => '减少金额'],
                                    [
                                        'name'    => 'yunfood/fund/record',
                                        'title'   => '账户记录',
                                        'ismenu'  => 0,
                                        'weigh'   => 100,
                                        'sublist' => [
                                            ['name' => 'yunfood/fund/record/index', 'title' => '查看'],
                                            ['name' => 'yunfood/fund/record/del', 'title' => '删除'],
                                        ]
                                    ],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/fund/order',
                                'title'   => '储值订单',
                                'icon'    => 'fa fa-list-alt',
                                'weigh'   => 80,
                                'sublist' => [
                                    ['name' => 'yunfood/fund/order/index', 'title' => '查看'],
                                    ['name' => 'yunfood/fund/order/add', 'title' => '新增'],
                                    ['name' => 'yunfood/fund/order/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/fund/order/del', 'title' => '删除'],
                                    ['name' => 'yunfood/fund/order/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/fund/pack',
                                'title'   => '储值套餐',
                                'icon'    => 'fa fa-cube',
                                'weigh'   => 70,
                                'sublist' => [
                                    ['name' => 'yunfood/fund/pack/index', 'title' => '查看'],
                                    ['name' => 'yunfood/fund/pack/add', 'title' => '新增'],
                                    ['name' => 'yunfood/fund/pack/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/fund/pack/del', 'title' => '删除'],
                                    ['name' => 'yunfood/fund/pack/multi', 'title' => '批量更新'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/order',
                        'title'   => '订单管理',
                        'icon'    => 'fa fa-list-alt',
                        'weigh'   => 100,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/order/main',
                                'title'   => '订单管理',
                                'icon'    => 'fa fa-list',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/order/main/index', 'title' => '查看'],
                                    ['name' => 'yunfood/order/main/add', 'title' => '新增'],
                                    ['name' => 'yunfood/order/main/edit', 'title' => '详情'],
                                    ['name' => 'yunfood/order/main/del', 'title' => '删除'],
                                    ['name' => 'yunfood/order/main/multi', 'title' => '批量更新'],
                                    ['name' => 'yunfood/order/main/change', 'title' => '修改价格'],
                                    ['name' => 'yunfood/order/main/manualCancel', 'title' => '取消订单'],
                                    ['name' => 'yunfood/order/main/markPayed', 'title' => '标记已支付'],
                                    ['name' => 'yunfood/order/main/markFinish', 'title' => '标记已完成'],
                                    ['name' => 'yunfood/order/main/print', 'title' => '打印订单'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/order/refund',
                                'title'   => '退款申请',
                                'icon'    => 'fa fa-bank',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/order/refund/index', 'title' => '查看'],
                                    ['name' => 'yunfood/order/refund/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/order/refund/del', 'title' => '删除'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/order/invoice',
                                'title'   => '发票申请',
                                'icon'    => 'fa fa-file-text',
                                'weigh'   => 80,
                                'sublist' => [
                                    ['name' => 'yunfood/order/invoice/index', 'title' => '查看'],
                                    ['name' => 'yunfood/order/invoice/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/order/invoice/del', 'title' => '删除'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/goods',
                        'title'   => '菜品管理',
                        'icon'    => 'fa fa-fire',
                        'weigh'   => 90,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/food/main',
                                'title'   => '菜品管理',
                                'icon'    => 'fa fa-list',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/food/main/index', 'title' => '查看'],
                                    ['name' => 'yunfood/food/main/add', 'title' => '新增'],
                                    ['name' => 'yunfood/food/main/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/food/main/del', 'title' => '删除'],
                                    ['name' => 'yunfood/food/main/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/food/category',
                                'title'   => '菜品分类',
                                'icon'    => 'fa fa-th-large',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/food/category/index', 'title' => '查看'],
                                    ['name' => 'yunfood/food/category/add', 'title' => '新增'],
                                    ['name' => 'yunfood/food/category/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/food/category/del', 'title' => '删除'],
                                    ['name' => 'yunfood/food/category/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/food/param',
                                'title'   => '菜品参数',
                                'icon'    => 'fa fa-list-alt',
                                'weigh'   => 80,
                                'sublist' => [
                                    ['name' => 'yunfood/food/param/index', 'title' => '查看'],
                                    ['name' => 'yunfood/food/param/add', 'title' => '新增'],
                                    ['name' => 'yunfood/food/param/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/food/param/del', 'title' => '删除'],
                                    ['name' => 'yunfood/food/param/multi', 'title' => '批量更新'],
                                    ['name' => 'yunfood/food/param/save', 'title' => '快捷新增'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/food/like',
                                'title'   => '菜品收藏',
                                'icon'    => 'fa fa-heart',
                                'weigh'   => 70,
                                'sublist' => [
                                    ['name' => 'yunfood/food/like/index', 'title' => '查看'],
                                    ['name' => 'yunfood/food/like/del', 'title' => '删除'],
                                    ['name' => 'yunfood/food/like/multi', 'title' => '批量更新'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/shop',
                        'title'   => '门店管理',
                        'icon'    => 'fa fa-user-secret',
                        'weigh'   => 80,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/shop/main',
                                'title'   => '门店管理',
                                'icon'    => 'fa fa-list',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/shop/main/index', 'title' => '查看'],
                                    ['name' => 'yunfood/shop/main/add', 'title' => '新增'],
                                    ['name' => 'yunfood/shop/main/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/shop/main/del', 'title' => '删除'],
                                    ['name' => 'yunfood/shop/main/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/shop/desk',
                                'title'   => '桌号管理',
                                'icon'    => 'fa fa-qrcode',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/shop/desk/index', 'title' => '查看'],
                                    ['name' => 'yunfood/shop/desk/add', 'title' => '新增'],
                                    ['name' => 'yunfood/shop/desk/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/shop/desk/del', 'title' => '删除'],
                                    ['name' => 'yunfood/shop/desk/multi', 'title' => '批量更新'],
                                    ['name' => 'yunfood/shop/desk/import', 'title' => '导入'],
                                    ['name' => 'yunfood/shop/desk/export', 'title' => '导出'],
                                    ['name' => 'yunfood/shop/desk/generate', 'title' => '批量生成桌号'],
                                    ['name' => 'yunfood/shop/desk/exportQrcode', 'title' => '导出点餐码'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/content',
                        'title'   => '内容管理',
                        'icon'    => 'fa fa-file',
                        'weigh'   => 50,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/slide',
                                'title'   => '轮播管理',
                                'icon'    => 'fa fa-image',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/slide/index', 'title' => '查看'],
                                    ['name' => 'yunfood/slide/add', 'title' => '新增'],
                                    ['name' => 'yunfood/slide/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/slide/del', 'title' => '删除'],
                                    ['name' => 'yunfood/slide/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/content/page',
                                'title'   => '单页管理',
                                'icon'    => 'fa fa-file-o',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/content/page/index', 'title' => '查看'],
                                    ['name' => 'yunfood/content/page/add', 'title' => '新增'],
                                    ['name' => 'yunfood/content/page/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/content/page/del', 'title' => '删除'],
                                    ['name' => 'yunfood/content/page/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/content/question',
                                'title'   => '常见问题',
                                'icon'    => 'fa fa-question-circle',
                                'weigh'   => 80,
                                'sublist' => [
                                    ['name' => 'yunfood/content/question/index', 'title' => '查看'],
                                    ['name' => 'yunfood/content/question/add', 'title' => '新增'],
                                    ['name' => 'yunfood/content/question/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/content/question/del', 'title' => '删除'],
                                    ['name' => 'yunfood/content/question/multi', 'title' => '批量更新'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/import_log',
                                'title'   => '导入日志',
                                'icon'    => 'fa fa-tint',
                                'weigh'   => 70,
                                'sublist' => [
                                    ['name' => 'yunfood/import_log/index', 'title' => '查看'],
                                    ['name' => 'yunfood/import_log/del', 'title' => '删除'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/printer',
                        'title'   => '打印设置',
                        'icon'    => 'fa fa-print',
                        'weigh'   => 45,
                        'sublist' => [
                            [
                                'name'    => 'yunfood/printer/config',
                                'title'   => '平台设置',
                                'icon'    => 'fa fa-cogs',
                                'weigh'   => 100,
                                'sublist' => [
                                    ['name' => 'yunfood/printer/config/index', 'title' => '基础设置'],
                                ]
                            ],
                            [
                                'name'    => 'yunfood/printer/device',
                                'title'   => '设备管理',
                                'icon'    => 'fa fa-list',
                                'weigh'   => 90,
                                'sublist' => [
                                    ['name' => 'yunfood/printer/device/index', 'title' => '查看'],
                                    ['name' => 'yunfood/printer/device/add', 'title' => '新增'],
                                    ['name' => 'yunfood/printer/device/edit', 'title' => '编辑'],
                                    ['name' => 'yunfood/printer/device/del', 'title' => '删除'],
                                    ['name' => 'yunfood/printer/device/multi', 'title' => '批量更新'],
                                    ['name' => 'yunfood/printer/device/testPrint', 'title' => '打印测试'],
                                ]
                            ],
                        ]
                    ],
                    [
                        'name'    => 'yunfood/feedback',
                        'title'   => '意见反馈',
                        'icon'    => 'fa fa-comments',
                        'weigh'   => 40,
                        'sublist' => [
                            ['name' => 'yunfood/feedback/index', 'title' => '查看'],
                            ['name' => 'yunfood/feedback/edit', 'title' => '编辑'],
                            ['name' => 'yunfood/feedback/del', 'title' => '删除'],
                        ]
                    ],
                ]
            ]
        ];
        Menu::create($menu);

        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('yunfood');

        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {

        Menu::enable('yunfood');

        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {

        Menu::disable('yunfood');

        return true;
    }

    /**
     */
    public function appInit()
    {
        // 添加命名空间
        if (! class_exists('\App\Config\YlyConfig')) {
            Loader::addNamespace('App', ADDON_PATH . 'yunfood' . DS . 'library' . DS . 'yilianyun' . DS . 'Lib' . DS);
        }
        if (! class_exists('\zhongwu\protocol\RpcClient')) {
            Loader::addNamespace('zhongwu', ADDON_PATH . 'yunfood' . DS . 'library' . DS . 'zhongwu' . DS);
        }
    }

    /**
     * @param $params
     */
    public function configInit(&$params)
    {

    }
}
